<?php
namespace app\admin\model;

use think\Model;
use think\Db;
use think\facade\Config;
class Redirect extends Model
{   
   
	/*查询数据 */
	public function get_data($page,$limit){

        $start=($page-1)*$limit;
        $list=Redirect::order('id', 'desc')->limit($start,$limit)->select()->toArray();
        $data['count']=Redirect::count();
        $data['list']=$list;

        return $data;
        
	}
	/*获取一条数据用于修改*/
	public function get_edit($id){
        $data=Redirect::where('id',$id)->find();
        return $data;  
	}
	/*新增*/
	public function insert_data($url,$r_url,$sm){
      $Redirect = new Redirect;
		$result=$Redirect->save([
            'url'  =>  trim($url),
            'r_url'  =>  trim($r_url),
		    'sm'  =>  trim($sm),
		]);
		return $result;
	}
	/*修改*/
	public function update_data($id,$url,$r_url,$sm){

      $data = new Redirect;
      // save方法第二个参数为更新条件
      $result=$data->save([
          'url'  => $url,
          'r_url'  => $r_url,
          'sm'  => $sm,
      ],['id' => $id]);
      
      
		return $result;    
	}
	/*删除假动作实际为修改操作*/
	public function delete_data($id){
        $result=Redirect::where('id','=',$id)->delete();
		return $result;
	}
}
 